﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace WpfApp2.Model
{
    public class RectangleElement : FrameworkElement
    {
        //DrawingVisual visual;
        //public RectangleElement()
        //{
        //    //Task.Run(() => {
        //    //}).Start();

        //    visual = new DrawingVisual();
        //    var drawingContext = visual.RenderOpen();
        //    drawingContext.DrawRectangle(Brushes.Red, null, new Rect(0, 0, 100, 20));

        //    string testString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor";

        //    // Create the initial formatted text string.
        //    FormattedText formattedText = new FormattedText(
        //        testString,
        //        CultureInfo.GetCultureInfo("en-us"),
        //        FlowDirection.LeftToRight,
        //        new Typeface("Verdana"),
        //        32,
        //        Brushes.Black);
        //    drawingContext.DrawText(formattedText, new Point(100, 100));
        //    drawingContext.Close();

        //    this.Dispatcher.BeginInvoke(new Action(() =>
        //    {
        //        this.AddVisualChild(visual);
        //    }));

        //}

        //protected override Visual GetVisualChild(int index)
        //{
        //    return visual;
        //}

        //protected override int VisualChildrenCount
        //{
        //    get
        //    {
        //        return 1;
        //    }
        //}
        BitmapImage bitmapImage = new BitmapImage(new Uri(@"https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png", UriKind.RelativeOrAbsolute));
        BitmapImage bitmapImage2 = new BitmapImage(new Uri(@"https://imusae-download.90sheji.com/imusae/download/2021/06/11/cbd8c76dc2b81d5104ee2dd214625dfc.png?sign=02d8e60dc8ba8bb07449068bfdcab201&t=61cdd780&imageMogr2/thumbnail/280x/crop/!x280-0a0/auto-orient/interlace/1/sharpen/1/quality/85/format/webp", UriKind.RelativeOrAbsolute));

        public int score = 0;
        public int score1 = 0;

        public int score2 = 0;

        public int score3 = 0;

        public int score4 = 0;

        public int x = 100;

        public int y = 100;

        [Obsolete]
        protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.DrawRectangle(Brushes.Red, null, new Rect(0, 0, 100, 20));
            string testString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor";
            testString = score.ToString();
            FormattedText formattedText = new(
                testString,
                CultureInfo.GetCultureInfo("en-us"),
                FlowDirection.LeftToRight,
                new Typeface("Verdana"),
                32,
                Brushes.Black);
            drawingContext.DrawText(formattedText, new Point(x - 60, y));

            //    var bitmapImage = new BitmapImage(new Uri("pack://application:,,,/1.jpg"));

            if (y > 300)
            {
                drawingContext.DrawImage(bitmapImage2, new Rect(x, y, 100, 100));
                drawingContext.DrawImage(bitmapImage2, new Rect(x + 300, y, 100, 100));
            }
            else
            {
                drawingContext.DrawImage(bitmapImage, new Rect(x, y, 100, 100));
                drawingContext.DrawImage(bitmapImage, new Rect(x + 300, y, 100, 100));
            }

            //drawingContext.DrawLine(new Pen(Brushes.Aqua, 5), new Point(200, 200), new Point(qx--, qy++));

            //drawingContext.DrawImage()
            //for (int i = 0; i < 100; i++)
            //{
            //    drawingContext.DrawText(formattedText, new Point(i, i));
            //    Thread.Sleep(1 * 1000);

            //}

            base.OnRender(drawingContext);
        }
        int qx = 100;int qy=0;
    }

}
